package com.fanrenqiji.modules.sys.dao;

import com.fanrenqiji.common.persistence.BaseDao;
import com.fanrenqiji.common.persistence.BaseDaoImpl;
import com.fanrenqiji.modules.sys.entity.Office;
import com.fanrenqiji.modules.sys.entity.User;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @author lijian E-mail:ljz0721cx@163.com
 * @version 创建时间：2015年1月16日 下午1:03:14
 * @description 直接使用spring的CrudRepository对于持久对象Crud操作
 */
public interface UserDao extends UserDaoCustom, CrudRepository<User, Long> {

	@Query("from User where loginName = ?1 and delFlag = '" + User.DEL_FLAG_NORMAL + "'")
	User findUserByLoginName(String username);

	@Modifying
	@Query("update User set loginIp=?1, loginDate=?2 where id = ?3")
	void updateLoginInfo(String host, Date date, Long id);

	@Modifying
	@Query("update User set password=?1 where id = ?2")
	public int updatePasswordById(String newPassword, Long id);

	User findByLoginName(String username);

	@Query("from User where office = ?1 and delFlag = '"
			+ User.DEL_FLAG_NORMAL + "'")
	List<User> findUserByOffice(Office office);
	
}


interface UserDaoCustom extends BaseDao<User> {
}

@Repository
class UserDaoImpl extends BaseDaoImpl<User> implements UserDaoCustom {

}